﻿using System;
using Avalonia.Controls;
using FluentAvalonia.UI.Controls;

namespace DocumentMaking.FluentNext.Dialogs;

public static class ErrorDialogStatic
{
    public static TaskDialog GetDialog(this Control control,Exception exception)
    {
        var td = new TaskDialog
        {
            Title = "文档生成工具",
            Content = exception.Message,
            IconSource = new SymbolIconSource(){Symbol = Symbol.Cancel},
            Header = "出问题了",
            FooterVisibility = TaskDialogFooterVisibility.Never,
            Buttons =
            {
                new TaskDialogButton("复制",true),
                new TaskDialogButton("退出",false)
            }
        };
        td.Closing += (sender, args) =>
        {
            if(args.Result is not bool b)return;
            if(!b)return;
            if(sender.Content is not string s)return;
            var top = TopLevel.GetTopLevel(control);
            top?.Clipboard?.SetTextAsync(s);
        };
        return td;
    }
    
    public static TaskDialog GetDialog(this Control control,string text)
    {
        var td = new TaskDialog
        {
            Title = "文档生成工具",
            Content = text,
            IconSource = new SymbolIconSource(){Symbol = Symbol.Cancel},
            Header = "出问题了",
            FooterVisibility = TaskDialogFooterVisibility.Never,
            Buttons =
            {
                new TaskDialogButton("复制",true),
                new TaskDialogButton("退出",false)
            }
        };
        td.Closing += (sender, args) =>
        {
            if(args.Result is not bool b)return;
            if(!b)return;
            if(sender.Content is not string s)return;
            var top = TopLevel.GetTopLevel(control);
            top?.Clipboard?.SetTextAsync(s);
        };
        return td;
    }
}